#include "RingQueue.hpp"
#include <pthread.h>
#include <unistd.h>

void *Productor(void *args)
{
    RingQueue<int> *rq = static_cast<RingQueue<int>*>(args);
    int cnt = 100;
    while(true)
    {
        rq->Push(cnt);
        cout << "product done, data is : " << cnt << endl;
        cnt--;
        //sleep(1);
    } 
}

void *Consumer(void *args)
{
    RingQueue<int> *rq = static_cast<RingQueue<int>*>(args);
    while(true)
    {
        sleep(1);
        int data = 0;
        rq->Pop(&data);
        cout << "consume done, data is : " << data << endl;
    }
}

int main()
{
    pthread_t c, p;
    RingQueue<int> *rq = new RingQueue<int>();

    pthread_create(&c, nullptr, Productor, rq);
    pthread_create(&p, nullptr, Consumer, rq);

    pthread_join(c, nullptr);
    pthread_join(p, nullptr);
    return 0;
}